Hello,
Object obj = null SystemAdmin - Tue Mar 26 04:51:47 EDT 2013 |
Re: Exception when adding something to an array |
Re: Exception when adding something to an array
I haven't looked at your code, but if I understand correctly then I think it might be better to use a skip list.
pragma runLim,0
DB db = null
DBE dbeResults = null
DBE dbeAttrs = null
string dummy[] = { }
Skip skipAttributes = createString
Module m = current Module
/**
getAttributes
**/
void getAttributes()
{
AttrDef ad = null
string attr = ""
int index = 0
for ad in m do
{
if (!ad.object) continue
put(skipAttributes, ad.name, ad.name)
}
for attr in skipAttributes do
{
insert(dbeAttrs, index, attr, iconNone)
index++
}
set(dbeAttrs, 0, true)
}
/**
doList
**/
void doList(DB db)
{
Buffer resBuf = create
string attr = get(dbeAttrs)
Module m = current
Object o = null
int count = 0
Skip attrValues = createString
string s = ""
for o in m do
{
s = o.attr""
if (find(attrValues, s, count))
{
delete(attrValues, s)
put(attrValues, s, count + 1)
}
else
{
put(attrValues, s, 1)
}
}
for count in attrValues do
{
resBuf += "\"" (string key attrValues) "\" (" count ")\n"
}
delete(attrValues)
attrValues = null
set(dbeResults, tempStringOf(resBuf))
delete(resBuf)
resBuf = null
}
/**
buildDialog
**/
void buildDialog()
{
db = create(current Module, "List Attribute Values")
label(db, "This utility lists all the different values found for the given attribute.\n")
dbeAttrs = listView(db, 0, 190, 15, dummy)
dbeResults = text(db, "Results", "", 60, 150, false)
apply(db,"OK", doList)
realize(db)
insertColumn(dbeAttrs, 0, "", 160, iconNone)
getAttributes()
show(db)
}
/**
listAttributeValues
**/
void listAttributeValues()
{
m = current Module
buildDialog()
}
listAttributeValues()
|
Re: Exception when adding something to an array |
Re: Exception when adding something to an array
//*********************
bool fPutSkipIncrement(Skip skpList, string KeyValue)
{ // Insert the KeyValue into the Skip list's 'Key'.
// The 'Data' portion of the Skip is set to 1 for new inserts and is
// incremented for already existing 'Key's in the Skip.
// 'Data' MUST be of type Integer.
// (represents the number of references).
// Return whether this is a first insert for KeyValue into the Skip.
bool IsNewValue = false
int NumReferences = 0 // Remains zero if next "find" doesn't find anything:
if(find(skpList, KeyValue, NumReferences))
delete(skpList, KeyValue) // Remove It
else IsNewValue = true // Mark it New
// ReInsert new or updated counts
NumReferences++
put (skpList, KeyValue, NumReferences)
return(IsNewValue)
} // end fPutSkipIncrement()
// Sample
Skip skp = create() // KEY: 'string' Values; DATA: 'int' Count Found
// Find
for whatever
{ find Value
fPutSkipIncrement(skp, Value)
}
// Report
int Count
for Count in skp do
{ Value = (string key skp)
print Count "\t# found for: " Value "\n"
}
|